﻿@model iMyRestaurent.Models.LocationModel

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Update</title>
    <script src="@Url.Content("~/Scripts/jquery-1.4.1.min.js")" type="text/javascript"></script>
    <style>
        #opacity-box
        {
            background-color: rgba(235, 190, 181, 0.5);
            border-radius: 10px 10px 10px 10px;
            margin: 0 auto;
            padding: 20px;
            width: 100%;
        }
        .button-style
        {
            background-color: rgba(243, 225, 147, 0.5);
            height: 40px;
        }
        
        .textbox-width
        {
            width: 315px;
        }
    </style>
    <script type="text/javascript">
        function ClearText(obj) {
            obj.value = "";
        }

        function Add() {
            var chairs = document.getElementsByName("C");
            for (var i = 0; i < chairs.length; i++) {
                if (chairs[i].value == "0") {
                    alert('This kind of table has been existed');
                    return;
                }
                if (chairs[i].value == "") {
                    alert('This kind of table not empty');
                    return;
                }
            }


            // Call AddRow action
            window.location = '@Url.Action("AddRow/")' + GetCurrentSet_Chairs() + '$' + GetCurrentSet_Number() + '$' + document.getElementById("Name").value + '$' + 'CreateFromSummary';
        }

        function Delete(id) {
            if (window.confirm('Do you want to delete this kind of table?')) {
                window.location = '@Url.Action("Delete/")' + id + '$' + GetCurrentSet_Chairs() + '$' + GetCurrentSet_Number() + '$' + document.getElementById("Name").value + '$' + 'CreateFromSummary';
            }
        }

        function Back() {
            window.location = '@Url.Action("Index","Summary")';
        }

        function Continue() {
            var name = document.getElementById("Name").value;
            if (name == '') {
                alert('Please input a name for the new location');
                return false;
            }
            // Check duplicate
            if (CheckDuplicate()) return false;
            // Call action Continue
            window.location = '@Url.Action("Continue/")' + GetCurrentSet_Chairs() + '$' + GetCurrentSet_Number() + '$' + document.getElementById("Name").value;
        }

        function GetCurrentSet_Chairs() {
            var chairs = document.getElementsByName("C");
            var strC = '';
            for (var i = 0; i < chairs.length; i++) {
                strC += chairs[i].value + ",";
            }

            return strC;
        }
        function GetCurrentSet_Number() {
            var number = document.getElementsByName("N");
            var strN = '';
            for (var i = 0; i < number.length; i++) {
                strN += number[i].value + ",";
            }

            return strN;
        }

        function CheckExistChairs(obj) {
            var chairs = document.getElementsByName("C");
            var count = 0;
            for (var i = 0; i < chairs.length; i++) {
                if ((chairs[i].value == obj.value) || (parseInt(chairs[i].value, 10) == parseInt(obj.value, 10))) {
                    count++;
                }
            }
            if (count > 1) {
                alert('This kind of table has been existed');
                obj.value = '';
                obj.focus();
                return false;
            }

            CheckIntValue(obj);
        }

        function CheckDuplicate() {
            // Check duplicate value
            var chairs = document.getElementsByName("C");
            for (var i = 0; i < chairs.length; i++) {
                var count = 0;
                for (var j = 0; j < chairs.length; j++) {
                    if (chairs[j].value == chairs[i].value) {
                        count++;
                    }
                }
                if (count > 1) {
                    alert('This kind of table duplicate');
                    chairs[i].value = '';
                    chairs[i].focus();
                    return true;
                }
            }

            return false;
        }
        function CheckIntValue(obj) {
            if (isNaN(obj.value)) {
                alert('Only Numeric Values Allowed');
                obj.value = '';
                obj.focus();
                return false;
            }
        }
        
    </script>
</head>
<body>
    <div>
        @using (Html.BeginForm())
        {
            <table width="1028" border="0" align="center" cellpadding="3" cellspacing="5">
                <tr>
                    <td valign="top" colspan="2" align="center">
                        <div style="font-weight: bold; font-size: xx-large">@Model.Title</div>
                    </td>
                </tr>
                <tr>
                    <td valign="top" colspan="2" align="center">
                        <div style="font-size: large">@Model.Desc</div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div id="opacity-box">
                            <div>@Html.LabelFor(x => x.Name) @Html.TextBoxFor(x => x.Name, new { @class = "textbox-width" })</div>
                            <div>
                                Quick table create selection</div>
                                @Html.Partial("Template",Model)
                            
                            <div style="text-align:center"><input type="button" name="btnAdd" value="Add" onclick="Add();" /></div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td valign="top" align="left">
                        <input type="button" value="Back" name="submitForm" onclick="window.location='@Url.Action("RedirectToSummaryScreen")'" />
                    </td>
                    <td valign="top" align="right">
                        <input type="button" value="Continue" name="submitForm" onclick="Continue();" />
                    </td>
                </tr>
            </table>
        }
    </div>
</body>
</html>
